package com.daos;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.model.Action;
import com.model.Role;

@Repository
public class RoleDao extends AbstractDao<Role>{

	@SuppressWarnings("unchecked")
	public List<Role> getRoles() {
		return hibernateTemplate.find("from Roles r order by r.name"); 
	}

	public Role getRoleByName(String name) {
		return (Role) hibernateTemplate.find("from Roles r where r.name = ?",name).get(0); 
	}

	@SuppressWarnings("unchecked")
	public List<Action> getActions() {
		return  (List<Action>) hibernateTemplate.find("from Actions action order by action.name"); 
	}

	@SuppressWarnings("unchecked")
	public List<Role> getRolesByUserId(int id) {
		return hibernateTemplate.find("SELECT  e.group.roles from Employees e where e.id = " +id);
	}

	@SuppressWarnings("unchecked")
	public List<Action> getActionsByRole(int id) {
		return  hibernateTemplate.find("SELECT  r.actions from Roles r where r.id = " +id);
		
	}
	
}
